﻿window.app = angular.module('app', ['ngResource']);

app.value('toastr', window.toastr);

app.config(['$routeProvider', '$locationProvider', '$httpProvider',
    function ($routeProvider, $locationProvider, $httpProvider) {

        $routeProvider.when('/', {
            redirectTo: '/home'
        });

        $routeProvider.when('/home', {
            templateUrl: 'Views/home.html',
            controller: 'HomeCtrl',
        });

        $routeProvider.when('/people', {
            templateUrl: 'Views/people.html',
            controller: 'PeopleCtrl',
            resolve: {
                people: ['Person', function(Person) {
                    return Person.all();
                }]
            }
        });

        $routeProvider.when('/about', {
            templateUrl: 'Views/about.html',
            controller: 'AboutCtrl',
        });

        $routeProvider.otherwise({
            redirectTo: '/'
        });

        $locationProvider.html5Mode(false).hashPrefix('!');
        $httpProvider.responseInterceptors.push('errorHttpInterceptor');
    }]);

app.run(['$rootScope', function($rootScope) {
    $rootScope.$on('$routeChangeSuccess', function(obj, arg) {
        $rootScope.templateUrl = arg.loadedTemplateUrl;
    });
}]);